package com.micro.ai.auth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.micro.ai.auth.entity.UserSession;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户会话Mapper接口
 * 
 * @author micro-ai
 * @since 0.0.1
 */
@Mapper
public interface UserSessionMapper extends BaseMapper<UserSession> {

    /**
     * 根据会话令牌查询会话
     * 
     * @param sessionToken 会话令牌
     * @return 会话信息
     */
    @Select("SELECT * FROM user_sessions WHERE session_token = #{sessionToken}")
    UserSession selectBySessionToken(@Param("sessionToken") String sessionToken);

    /**
     * 根据用户ID查询有效会话列表
     * 
     * @param userId 用户ID
     * @return 会话列表
     */
    @Select("SELECT * FROM user_sessions WHERE user_id = #{userId} AND expires_at > NOW() ORDER BY created_at DESC")
    List<UserSession> selectActiveByUserId(@Param("userId") String userId);
}

